/******************************************************************************
 * * call_proc.c - process user key action of call module
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/

#include "call_global.h"

/**
 * Process user key of Call_Main UI
 * paras(in) void
 * return void
 */
static VOID Call_Mute_Swap(VOID)
{
    if (FALSE == g_MMI_Call_Mng.IsMute)
    {
        g_MMI_Call_Mng.IsMute = TRUE;
        MMI_Modem_Call_Request_Set_Mute(g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->SimId, TRUE);
        Display_Call_Mute();
    }
    else
    {
        g_MMI_Call_Mng.IsMute = FALSE;
        MMI_Modem_Call_Request_Set_Mute(g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->SimId, FALSE);
        Display_Call_Unmute();
    }
}

/**
 * Process DTMF tone
 *
 * param (in) Dtmf:  MMI_MODEM_CALL_REQUEST_DTMF *
 * return  void
 */
static INT8 Call_Proc_Dtmf(UI_KEY_VALUE Key_Val)
{
    INT8                          Num;
    MMI_Modem_Call_Request_Dtmf_t *DtmfReq;

    switch (Key_Val)
    {
    case KEY_0:
        Num = '0';
        break;

    case KEY_1:
        Num = '1';
        break;

    case KEY_2:
        Num = '2';
        break;

    case KEY_3:
        Num = '3';
        break;

    case KEY_4:
        Num = '4';
        break;

    case KEY_5:
        Num = '5';
        break;

    case KEY_6:
        Num = '6';
        break;

    case KEY_7:
        Num = '7';
        break;

    case KEY_8:
        Num = '8';
        break;

    case KEY_9:
        Num = '9';
        break;

    case KEY_HASH:
        Num = '#';
        break;

    case KEY_ASTERISK:
        Num = '*';
        break;

    default:
        UI_Log_Out(UI_SUB_MODULE_CALL, UI_LOG_LEVEL_ERROR, "Wrong key %d", Key_Val);
        return(0xFF);  // invalid input
    } /* switch */

    DtmfReq = (MMI_Modem_Call_Request_Dtmf_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Call_Request_Dtmf_t));
    Hal_Mem_Set(DtmfReq, 0, sizeof(MMI_Modem_Call_Request_Dtmf_t));

    DtmfReq->dtmf     = Num;
    DtmfReq->duration = UI_CALL_DTMF_DURATION;  // todo:: is start and stop needed?
    MMI_Modem_Call_Request_Dtmf(g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->SimId, DtmfReq);
    return(Num);
} /* Call_Proc_Dtmf */

/**
 * stop ring
 * param (in) void
 * return  void
 */
VOID Call_Stop_Ring(VOID)
{
    If_Setting_Play_Tone_t *PlayToneReq;

    // play tone
    PlayToneReq           = (If_Setting_Play_Tone_t *)Hal_Mem_Alloc(sizeof(If_Setting_Play_Tone_t));
    PlayToneReq->SimId    = g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->SimId;
    PlayToneReq->ToneType = IF_SETTING_TONS_TYPE_CALL;
    PlayToneReq->PlayCtrl = IF_SETTING_PLAY_TONS_STOP;
    Setting_Play_Tone_Req(PlayToneReq);
}

/**
 * proc Call end
 * param (in) IsMoCall:  BOOL  ture means MT call in coming state
 * return  void
 */
VOID Call_Proc_End(VOID)
{
    MMI_MODEM_SIM_ID SimId = g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->SimId;

    if (Call_Is_Call_Waiting_Present())
    {
        MMI_Modem_Call_Request_Udub(SimId);
        g_MMI_Call_Mng.CallProcess = UI_CALL_PROCESS_MT_REJECT;
        return;
    }

    printf("%s: state=%d, index=%d\n", __FUNCTION__,
        g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->State,
        g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->Index);

    switch (g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->State)
    {
    case MMI_MODEM_CALL_STATE_NULL:
    case MMI_MODEM_CALL_STATE_WAITING:
        break;

    case MMI_MODEM_CALL_STATE_ACTIVE:
        MMI_Modem_Call_Request_Hangup_Foreground_Resume_Background(SimId);
        break;

    case MMI_MODEM_CALL_STATE_HOLDING:
        MMI_Modem_Call_Request_Hangup_Waiting_Or_Background(SimId);
        break;

    case MMI_MODEM_CALL_STATE_INCOMING:
        MMI_Modem_Call_Request_Udub(SimId);
        g_MMI_Call_Mng.CallProcess = UI_CALL_PROCESS_MT_REJECT;
        break;

    default:
        MMI_Modem_Call_Request_Hangup(SimId, g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->Index);
        break;
    }
}

/**
 * check status of SIM
 * param(in) void:
 * return UINT8 CALL_SIM_STATUS
 */
static CALL_SIM_STATUS Call_Get_Sim_Status(VOID)
{
    CALL_SIM_STATUS SimStatus = CALL_NO_SIM_PRESENT;

    if (MMI_Modem_Sim_Present_Check_Req(MMI_MODEM_SIM_1))
    {
        SimStatus |= CALL_SIM1_PRESENT;
    }

    if (MMI_Modem_Sim_Present_Check_Req(MMI_MODEM_SIM_2))
    {
        SimStatus |= CALL_SIM2_PRESENT;
    }

    return(SimStatus);
}

/**
 * Call Modem adapter interface to make call
 * param(in) void:
 * return void
 */
static VOID Call_Make_Call(MMI_MODEM_SIM_ID SimId)
{
    MMI_MODEM_CALL_SERVICE_TYPE CallType;
    INT8                        *Number, *TmpNumber;

    Hal_Set_Voice_Call_Status(VOICE_CALL_START);
    g_MMI_Call_Mng.FromAct = Nav_Get_Top();
    printf("Call_Make_Call: FromAct=%d\n", g_MMI_Call_Mng.FromAct);

    g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->SimId = SimId;

    TmpNumber = g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->Number;
    Number    = (INT8 *)Hal_Mem_Alloc(strlen(TmpNumber) + 1);
    Hal_Mem_Set(Number, 0, strlen(TmpNumber) + 1);
    Hal_Mem_Copy(Number, TmpNumber, strlen(TmpNumber));

    if (FALSE == g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->IsECall)
    {
        CallType = MMI_MODEM_CALL_SERVICE_NORMAL;
        Display_Call_Calling();
    }
    else
    {
        CallType = MMI_MODEM_CALL_SERVICE_EMERGENCY;
        Display_Call_Emergency_Calling();
    }

    MMI_Modem_Call_Request_Dial(SimId, Number, CallType);
}

/**
 * start call proceding
 * param(in) void:
 * return void
 */
VOID Call_Start_Call(VOID)
{
    IF_SETTING_DEFAULT_SIM DefaultSim;
    CALL_SIM_STATUS        SimStatus;
    MMI_MODEM_SIM_ID       TmpSimId;

    SimStatus = Call_Get_Sim_Status();
    Audio_Player_Audio_Stop();
    if (CALL_BOTH_SIM_PRESENT == SimStatus)
    {   // both sim present
        DefaultSim = Setting_Get_Default_Sim_Req(IF_SETTING_SERVICE_CALL);

        if (IF_SETTING_ASK_EVERY_TIME == DefaultSim)
        {
            Display_Dial_Call_Select_Sim();
            return;
        }
        else
        {
            if (IF_SETTING_DEFAULT_SIM_1 == DefaultSim)
            {
                TmpSimId = MMI_MODEM_SIM_1;
            }
            else
            {
                TmpSimId = MMI_MODEM_SIM_2;
            }
        }
    }
    else if (CALL_SIM1_PRESENT == SimStatus)
    {
        TmpSimId = MMI_MODEM_SIM_1;
    }
    else if (CALL_SIM2_PRESENT == SimStatus)
    {
        TmpSimId = MMI_MODEM_SIM_2;
    }
    else
    {
        if (TRUE == g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->IsECall)
        {
            // emergency call ,use SIM1 as default SIM
            TmpSimId = MMI_MODEM_SIM_1;
        }
        else
        {
            Call_Clear_Call_Paras(g_MMI_Call_Mng.ActiveIndex);
            Display_Call_Emergency_Only_Info();
            Audio_Player_Audio_Contine();
            return;
        }
    }

    Call_Make_Call(TmpSimId);
}     /* Call_Start_Call */

/**
 * Process user key of Call_Calling UI
 *
 */
static VOID Call_Adjust_SPK_Vol(UINT8 VolCtrl)
{
    UINT8 CurrentVol;

    // show volume bar
    lv_obj_t * VolBar = ((UI_Normal_NoTitle_Labels_Bar_Desc_t *)(g_MMI_Call_Mng.CurrentDesc))->Bar.Bar;
    lv_obj_set_hidden(VolBar, FALSE);

    #if USE_LV_BLUETOOTH
    extern INT8 last_volume;
    if(bt_get_headset_connect())
    {
        CurrentVol = last_volume;
        lv_slider_set_range(VolBar, 0, HAL_BT_VOLUME_MAX);
        lv_slider_set_value(VolBar, CurrentVol, LV_ANIM_OFF);
        if (UI_CALL_SPK_VOL_UP == VolCtrl)
        {
            if (CurrentVol == HAL_BT_VOLUME_MAX)
            {   // max, no need set
                return;
            }
            CurrentVol += 1;
        }
        else
        {
            if (CurrentVol == 0)
            {   // min, no need set
                return;
            }
            CurrentVol -= 1;
        }
        appbt_hfp_set_speaker_gain(CurrentVol);
        last_volume = CurrentVol;
        return;
    }
    #endif

    if (HAL_CALL_SPK_OFF == g_MMI_Call_Mng.CallSpkStatus)
    {        // speaker off, set handset nv
        UI_NV_Read_Req(NV_SECTION_UI_CALL, CALL_NV_HANDSET_OFFSET, 1, &CurrentVol);
    }
    else
    {        // speaker on, set speaker nv
        UI_NV_Read_Req(NV_SECTION_UI_CALL, CALL_NV_SPEAKER_OFFSET, 1, &CurrentVol);
    }

    lv_slider_set_range(VolBar, UI_CALL_SPK_VOL_LEVEL_MUTE, UI_CALL_SPK_VOL_LEVEL_MAX);
    lv_slider_set_value(VolBar, CurrentVol, LV_ANIM_OFF);

    if (UI_CALL_SPK_VOL_UP == VolCtrl)
    {
        if (CurrentVol == UI_CALL_SPK_VOL_LEVEL_MAX)
        {   // max, no need set
            return;
        }
        CurrentVol += 1;
    }
    else
    {
        if (CurrentVol == UI_CALL_SPK_VOL_LEVEL_MUTE)
        {   // min, no need set
            return;
        }
        CurrentVol -= 1;
    }

    Hal_Call_Speaker((HAL_CALL_SPEAKER)g_MMI_Call_Mng.CallSpkStatus, (HAL_SPEAKER_GAIN)CurrentVol);

    if (HAL_CALL_SPK_OFF == g_MMI_Call_Mng.CallSpkStatus)
    {        // speaker off, set handset nv
        UI_NV_Write_Req(NV_SECTION_UI_CALL, CALL_NV_HANDSET_OFFSET, 1, &CurrentVol);
    }
    else
    {        // speaker on, set speaker nv
        UI_NV_Write_Req(NV_SECTION_UI_CALL, CALL_NV_SPEAKER_OFFSET, 1, &CurrentVol);
    }
} /* Call_Adjust_SPK_Vol */

/**
 * Process user key of Call_Calling UI
 *
 */
UINT8 Call_Key_Proc_Calling(lv_obj_t *obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_SOFTRIGHT:
        case KEY_END:
        {
            Call_Proc_End();
            return(1);
        }

        case KEY_LEFT:
            Call_Adjust_SPK_Vol(UI_CALL_SPK_VOL_DOWN);
            break;

        case KEY_RIGHT:
            Call_Adjust_SPK_Vol(UI_CALL_SPK_VOL_UP);
            break;

        default:
            break;
        } /* switch */
    }

    return(0);
} /* Call_Key_Proc_Calling */

/**
 * Process user key of Call_Main UI
 *
 */
UINT8 Call_Key_Proc_Main(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_SOFTRIGHT:
        {
            if (TRUE == Call_Is_Call_Waiting_Present())
            {       // the other call is in waiting state
                g_MMI_Call_Mng.CallProcess = UI_CALL_PROCESS_SWAP;
                MMI_Modem_Call_Request_Switch_Waiting_Or_Holding_And_Active(g_MMI_Call_Mng.Calls[
                                                                                Call_Get_Waiting_Param_Index()]->SimId);
            }
            else
            {
                if (g_MMI_Call_Mng.CallSpkStatus == HAL_CALL_SPK_OFF)
                {
                    Display_Call_Loudsp_Inquire();
                }
                else
                {
                    Call_Spk_Ctrl(FALSE);
                    Display_Call_Loudsp_Off();
                }
            }
            return(1);
        }

        case KEY_SOFTLEFT:
            if (FALSE == g_MMI_Call_Mng.IsConnect)
            {   // there is no connect, ignore this key event
                return(1);
            }
            Display_Call_Opt();
            return(1);

        case KEY_DIAL:
            if (TRUE == Call_Is_Call_Waiting_Present())
            {       // the other call is in waiting state
                g_MMI_Call_Mng.CallProcess = UI_CALL_PROCESS_SWAP;
                MMI_Modem_Call_Request_Switch_Waiting_Or_Holding_And_Active(g_MMI_Call_Mng.Calls[
                                                                                Call_Get_Waiting_Param_Index()]->SimId);
            }
            break;

        case KEY_END:
            Call_Proc_End();
            return(1);

        case KEY_LEFT:
            Call_Adjust_SPK_Vol(UI_CALL_SPK_VOL_DOWN);
            break;

        case KEY_RIGHT:
            Call_Adjust_SPK_Vol(UI_CALL_SPK_VOL_UP);
            break;

        default:
            Display_Call_Dtmf_Input(Call_Proc_Dtmf(Key_Val)); // display dtmf input UI with first num
            return(1);
        }                                                     /* switch */
    }

    return(0);
} /* Call_Key_Proc_Main */

/**
 * Process user key of Call_Incoming UI
 *
 */
UINT8 Call_Key_Proc_Incoming(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    lv_obj_t                            *Txt;
    UI_Normal_NoTitle_Labels_Bar_Desc_t *pDesc;

    pDesc = (UI_Normal_NoTitle_Labels_Bar_Desc_t *)(g_MMI_Call_Mng.CurrentDesc);

    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_SOFTRIGHT:
        {       // silent
            Txt = lv_obj_get_child(pDesc->ButtonBar.ButtonR.Button, NULL);
            lv_label_set_text(Txt, "");
            printf("silent btn has been pressed in %s\n",__FUNCTION__);
            Call_Stop_Ring();
            Audio_Player_Audio_Stop();
            break;
        }

        case KEY_END:
            Call_Stop_Ring();
            Call_Proc_End();
            break;

        case KEY_DIAL:
            Hal_Set_Voice_Call_Status(VOICE_CALL_START);
            MMI_Modem_Call_Request_Answer(g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex]->SimId);
            Call_Stop_Ring();
            Audio_Player_Audio_Stop();
            Nav_Back(ACT_ID_ANY);               // pop incoming ui
            Display_Call_Main();
            return(1);

        default:
            break;
        }     /* switch */
    }

    return(0);
}

/**
 * Process user key of Call_Opt UI
 *
 */
UINT8 Call_Key_Proc_Opt(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_SOFTRIGHT:
        {       // EXIT
            Nav_Back(ACT_ID_ANY);
            return(1);
        }

        case KEY_END:
            Call_Proc_End();
            return(1);

        default:
            break;
        }     /* switch */
    }

    return(0);
}

/**
 * Process user key of Call_Loudsp Inquire UI
 *
 */
UINT8 Call_Key_Proc_Loudsp_Inquire(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_SOFTRIGHT:
            Nav_Back(ACT_ID_ANY);
            break;

        case KEY_OK:
        {           // turn on call speaker and display Loudsp on UI
            Nav_Back(ACT_ID_ANY);
            Call_Spk_Ctrl(TRUE);
            Display_Call_Loudsp_On();
            break;
        }

        default:
            break;
        }     /* switch */
    }

    return(1);
}

/**
 * Process user key of Call_Loudsp Inquire UI
 *
 */
UINT8 Call_Key_Proc_Emergency_Calling(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_SOFTRIGHT:
        case KEY_END:
            Call_Proc_End();
            break;

        default:
            break;
        }     /* switch */
    }

    return(1);
}

/**
 * Process user key of call select sim
 *
 */
UINT8 Call_Key_Proc_Select_Sim(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    lv_obj_t    *Btn;
    lv_event_cb_t BtnAct;

    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_DIAL:
        {
            Btn    = lv_list_get_btn_selected(Obj);
            BtnAct = lv_obj_get_event_cb(Btn);

            if (NULL != BtnAct)
            {
                BtnAct(Btn, LV_EVENT_CLICKED);
            }
            else
            {
                UI_Log_Out(UI_SUB_MODULE_CALL, UI_LOG_LEVEL_ERROR, "click action should not be NULL, %s, %d\n", __FILE__, __LINE__);
            }
            return(1);
        }

        case KEY_SOFTRIGHT:
        {
            Call_Clear_Call_Paras(g_MMI_Call_Mng.ActiveIndex);
            Nav_Back(ACT_ID_ANY);
            return(1);
        }

        case KEY_END:
            Call_Clear_Call_Paras(g_MMI_Call_Mng.ActiveIndex);
            //Call_UI_Go_Back();
            Nav_Back(ACT_ID_ANY);
            return(1);

        default:
            break;
        }   /* switch */
    }

    return(0);
} /* Call_Key_Proc_Select_Sim */

/**
 * Process user key of call DTMF Input
 *
 */
UINT8 Call_Key_Proc_Dtmf_Input(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_OK:
            Nav_Back(ACT_ID_ANY);                      // distroy call main
            return(1);

        case KEY_SOFTLEFT:
            if (FALSE == g_MMI_Call_Mng.IsConnect)
            {   // there is no connect, ignore this key event
                return(1);
            }
            Display_Call_Opt();
            return(1);

        case KEY_END:
            Call_Proc_End();
            break;

        case KEY_0:
        case KEY_1:
        case KEY_2:
        case KEY_3:
        case KEY_4:
        case KEY_5:
        case KEY_6:
        case KEY_7:
        case KEY_8:
        case KEY_9:
        case KEY_HASH:
        case KEY_ASTERISK:
            Call_Proc_Dtmf(Key_Val);
            break;

        default:
            break;
        }     /* switch */
    }

    return(0);
} /* Call_Key_Proc_Dtmf_Input */

/**
 * rel func for sim select SIM1
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Sim_Sel_Sim1(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    Nav_Back(ACT_ID_ANY);
    Call_Make_Call(MMI_MODEM_SIM_1);
} /* Call_Key_Proc_Main */

/**
 * rel func for sim select SIM2
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Sim_Sel_Sim2(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    Nav_Back(ACT_ID_ANY);
    Call_Make_Call(MMI_MODEM_SIM_2);
} /* Call_Key_Proc_Main */

/**
 * rel func for Call Option Hold
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Hold(lv_obj_t *Obj, lv_event_t e)
{
#if 0
    UI_Call_Params_t *CallParams = g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.ActiveIndex];

    Nav_Back(ACT_ID_ANY);

    if (MMI_MODEM_CALL_STATE_HOLDING == CallParams->State)
    {
        g_MMI_Call_Mng.CallProcess = UI_CALL_PROCESS_UNHOLD;
    }
    else
    {
        g_MMI_Call_Mng.CallProcess = UI_CALL_PROCESS_HOLD;
    }

    MMI_Modem_Call_Request_Switch_Waiting_Or_Holding_And_Active(CallParams->SimId);
#endif
} /* Call_Rel_Func_Call_Opt_Hold */

/**
 * rel func for Call Option answer
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Answer(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    UINT8 ParamIndex = Call_Get_Waiting_Param_Index();

    Nav_Back(ACT_ID_ANY);
    MMI_Modem_Call_Request_Switch_Waiting_Or_Holding_And_Active(g_MMI_Call_Mng.Calls[ParamIndex]->SimId);
}

/**
 * rel func for Call Option reject
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Reject(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    UINT8 ParamIndex = Call_Get_Waiting_Param_Index();

    Nav_Back(ACT_ID_ANY);                                                   // distroy calling interface
    MMI_Modem_Call_Request_Udub(g_MMI_Call_Mng.Calls[ParamIndex]->SimId);
    g_MMI_Call_Mng.CallProcess = UI_CALL_PROCESS_MT_REJECT;
}

/**
 * rel func for Call Option End Active Call
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_End_Act(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    Nav_Back(ACT_ID_ANY);
    MMI_Modem_Call_Request_Hangup_Foreground_Resume_Background(g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.
                                                                                        ActiveIndex]->SimId);
} /* Call_Rel_Func_Call_Opt_Hold */

/**
 * rel func for Call Option Swap
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Swap(lv_obj_t *Obj, lv_event_t e)
{
#if 0
    Nav_Back(ACT_ID_ANY);
    g_MMI_Call_Mng.CallProcess = UI_CALL_PROCESS_SWAP;
    MMI_Modem_Call_Request_Switch_Waiting_Or_Holding_And_Active(g_MMI_Call_Mng.Calls[g_MMI_Call_Mng.
                                                                                         ActiveIndex]->SimId);
#endif
} /* Call_Rel_Func_Call_Opt_Hold */

/**
 * rel func for Call Option Conference
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Conference(lv_obj_t *Obj, lv_event_t e)
{
    // todo:: low priority, implement in next step
} /* Call_Rel_Func_Call_Opt_Hold */

/**
 * rel func for Call Option End all calls
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_End_All(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    Nav_Back(ACT_ID_ANY);
    MMI_Modem_Call_Request_Hangup(g_MMI_Call_Mng.Calls[0]->SimId, g_MMI_Call_Mng.Calls[0]->Index);
    MMI_Modem_Call_Request_Hangup(g_MMI_Call_Mng.Calls[1]->SimId, g_MMI_Call_Mng.Calls[1]->Index);
} /* Call_Rel_Func_Call_Opt_Hold */

/**
 * rel func for Call Option Contacts
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Contacts(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    // call contacts api to enter contack APP
    Nav_Back(ACT_ID_ANY);
    Contacts_Select_Contact_Req(IF_CONTACTS_CALL_SEL_ONE_CONTACT);
} /* Call_Rel_Func_Call_Opt_Hold */

/**
 * rel func for Call Option Menu
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Menu(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    // call framework api to display menu
    Nav_Back(ACT_ID_ANY);
    Framework_Call_Menu_Main();
} /* Call_Rel_Func_Call_Opt_Hold */

/**
 * rel func for Call Option Mute
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Mute(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    Nav_Back(ACT_ID_ANY);
    Call_Mute_Swap();
} /* Call_Rel_Func_Call_Opt_Hold */

/**
 * rel func for Call Option Loudsp
 * param(in) Obj: lv_obj_t
 * return: lv_res_t
 */
VOID Call_Rel_Func_Call_Opt_Loudsp(lv_obj_t *Obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) {
        return;
    }

    Nav_Back(ACT_ID_ANY);
    // swap speaker status
    if (HAL_CALL_SPK_OFF == g_MMI_Call_Mng.CallSpkStatus)
    {
        Display_Call_Loudsp_On();
        Call_Spk_Ctrl(TRUE);
    }
    else
    {
        Display_Call_Loudsp_Off();
        Call_Spk_Ctrl(FALSE);
    }
}
